home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / idl / nsIUnicharInputStream.idl < prev    next >
Text File  |  2006-05-08  |  6KB  |  156 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. #include "nsISupports.idl"
  39.  
  40. interface nsIUnicharInputStream;
  41.  
  42. %{C++
  43. /**
  44.  * The signature of the writer function passed to ReadSegments. This
  45.  * is the "consumer" of data that gets read from the stream's buffer.
  46.  *
  47.  * @param aInStream stream being read
  48.  * @param aClosure opaque parameter passed to ReadSegments
  49.  * @param aFromSegment pointer to memory owned by the input stream
  50.  * @param aToOffset amount already read (since ReadSegments was called)
  51.  * @param aCount length of fromSegment
  52.  * @param aWriteCount number of bytes read
  53.  *
  54.  * Implementers should return the following:
  55.  *
  56.  * @return NS_OK and (*aWriteCount > 0) if consumed some data
  57.  * @return <any-error> if not interested in consuming any data
  58.  *
  59.  * Errors are never passed to the caller of ReadSegments.
  60.  *
  61.  * NOTE: returning NS_OK and (*aWriteCount = 0) has undefined behavior.
  62.  */
  63. typedef NS_CALLBACK(nsWriteUnicharSegmentFun)(nsIUnicharInputStream *aInStream,
  64.                                               void *aClosure,
  65.                                               const PRUnichar *aFromSegment,
  66.                                               PRUint32 aToOffset,
  67.                                               PRUint32 aCount,
  68.                                               PRUint32 *aWriteCount);
  69. %}
  70. native nsWriteUnicharSegmentFun(nsWriteUnicharSegmentFun);
  71.  
  72. /**
  73.  * Abstract unicode character input stream
  74.  * @see nsIInputStream
  75.  */
  76. [scriptable, uuid(d5e3bd80-6723-4b92-b0c9-22f6162fd94f)]
  77. interface nsIUnicharInputStream : nsISupports {
  78.   /**
  79.    * Reads into a caller-provided character array.
  80.    *
  81.    * @return The number of characters that were successfully read. May be less
  82.    *         than aCount, even if there is more data in the input stream.
  83.    *         A return value of 0 means EOF.
  84.    *
  85.    * @note To read more than 2^32 characters, call this method multiple times.
  86.    */
  87.   [noscript] unsigned long read([array, size_is(aCount)] in PRUnichar aBuf,
  88.                                 in unsigned long aCount);
  89.  
  90.   /**
  91.    * Low-level read method that has access to the stream's underlying buffer.
  92.    * The writer function may be called multiple times for segmented buffers.
  93.    * ReadSegments is expected to keep calling the writer until either there is
  94.    * nothing left to read or the writer returns an error.  ReadSegments should
  95.    * not call the writer with zero characters to consume.
  96.    *
  97.    * @param aWriter the "consumer" of the data to be read
  98.    * @param aClosure opaque parameter passed to writer 
  99.    * @param aCount the maximum number of characters to be read
  100.    *
  101.    * @return number of characters read (may be less than aCount)
  102.    * @return 0 if reached end of file (or if aWriter refused to consume data)
  103.    *
  104.    * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
  105.    *   block the calling thread (non-blocking mode only)
  106.    * @throws <other-error> on failure
  107.    *
  108.    * NOTE: this function may be unimplemented if a stream has no underlying
  109.    * buffer
  110.    */
  111.   [noscript] unsigned long readSegments(in nsWriteUnicharSegmentFun aWriter,
  112.                                         in voidPtr aClosure,
  113.                                         in unsigned long aCount);
  114.  
  115.   /**
  116.    * Read into a string object.
  117.    * @param aCount The number of characters that should be read
  118.    * @return The number of characters that were read.
  119.    */
  120.   unsigned long readString(in unsigned long aCount, out AString aString);
  121.  
  122.  /**
  123.   * Close the stream and free associated resources. This also closes the
  124.   * underlying stream, if any.
  125.   */
  126.   void close();
  127. };
  128.  
  129. %{C++
  130. #include "nsStringFwd.h"
  131. class nsIInputStream;
  132.  
  133. /**
  134.  * Create a nsIUnicharInputStream that wraps up a string. Data is fed
  135.  * from the string out until the done. When this object is destroyed
  136.  * it destroys the string by calling |delete| on the pointer if
  137.  * aTakeOwnership is set.  If aTakeOwnership is not set, you must
  138.  * ensure that the string outlives the stream!
  139.  */
  140. extern NS_COM nsresult
  141.   NS_NewStringUnicharInputStream(nsIUnicharInputStream** aInstancePtrResult,
  142.                                  const nsAString* aString,
  143.                                  PRBool aTakeOwnership);
  144.  
  145. /**
  146.  * Create a new nsUnicharInputStream that provides a converter for the
  147.  * byte input stream aStreamToWrap. If no converter can be found then
  148.  * nsnull is returned and the error code is set to
  149.  * NS_INPUTSTREAM_NO_CONVERTER.
  150.  */
  151. extern NS_COM nsresult
  152.   NS_NewUTF8ConverterStream(nsIUnicharInputStream** aInstancePtrResult,
  153.                             nsIInputStream* aStreamToWrap,
  154.                             PRInt32 aBufferSize = 0);
  155. %}
  156.